﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ModelGymTauro;

namespace ViewGymTauro
{
    public partial class Membresia_nueva : Form
    {
        public List<Membresia> lista = new List<Membresia>();
        public Membresia_nueva()
        {
            InitializeComponent();
            lista = IniciaSesion.gymMan.queryAllMembresia();
            refreshMembresia();
        }

        public void refreshMembresia() {
            dataGridView1.Rows.Clear();
            lista = IniciaSesion.gymMan.queryAllMembresia();
            for (int i = 0; i < lista.Count; i++) {
                dataGridView1.Rows.Add(new string[] { lista[i].Id.ToString(), lista[i].Nombre.ToString(), lista[i].Periodo.ToString(), lista[i].Costo.ToString() });
            
            
            }
        
        
        }

        

        
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Membresia m = lista[e.RowIndex];
            this.txtName.Text=m.Nombre;
            this.txtCosto.Text=m.Costo.ToString();
            this.txtPeriod.Text=m.Periodo;
            this.txtName.Enabled = false;
            this.txtCosto.Enabled = false;
            this.txtPeriod.Enabled = false;
        }

        

        private void btnEdit_Click(object sender, EventArgs e)
        {
            this.txtName.Enabled = true;
            this.txtCosto.Enabled = true;
            this.txtPeriod.Enabled = true;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Membresia m = new Membresia();
            m.Nombre = this.txtName.Text;
            m.Periodo = this.txtPeriod.Text;
            m.Costo = float.Parse(this.txtCosto.Text);
            IniciaSesion.gymMan.addTipoMembresia(m);
            refreshMembresia();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            this.txtName.Text = "";
            this.txtCosto.Text = "";
            this.txtPeriod.Text = "";
        }
    }
}
